<?php

/**
 * Document form.
 *
 * @package    form
 * @subpackage Document
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class DocumentForm extends BaseDocumentForm
{
  public function configure()
  {
    $this->widgetSchema['type']    = new sfWidgetFormChoice(array('choices' => DocumentTable::$types));
    $this->validatorSchema['type'] = new sfValidatorChoice(array('choices' => array_keys(DocumentTable::$types)));

    if ($this->getObject()->getType())
    {
      $this->embedForm('object', $this->getTypeForm());
    }
  }

  public function getTypeForm()
  {
    $class = sprintf('%sForm', $this->getObject()->getType());

    $form = new $class($this->getObject()->getTypeObject());

    return $form;
  }
}
